import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
// import 'package:provider/provider.dart';
import '../../provider/cart.dart';

class CartBottom extends StatelessWidget {

  CartProvider cartProvider;

  CartBottom({Key key, this.cartProvider}) : super(key:key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenUtil().setWidth(750),
      color: Colors.white,
      padding: EdgeInsets.all(5),
      child: Row(
        children: <Widget>[
          _selectAllBtn(context),
          _allPriceArea(),
          _submitButton(),
        ],
      ),
    );
  }

  // 全选按钮
  Widget _selectAllBtn(context) {
    return Container(
      child: Row(
        children: <Widget>[
          Checkbox(
            value: cartProvider.isAllCheck,
            activeColor: Colors.pink,
            onChanged: (bool val) {
              cartProvider.changeAllCheckState(val);
            },
          ),
          Text('全选'),
        ],
      ),
    );
  }

  // 合计区域
  Widget _allPriceArea() {
    
    return Container(
      width: ScreenUtil().setWidth(405),
      alignment: Alignment.centerRight,
      child: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              Container(
                alignment: Alignment.centerRight,
                width: ScreenUtil().setWidth(225),
                child: Text(
                  '合计：',
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(36)
                  ),
                ),
              ),
              Container(
                alignment: Alignment.center ,
                width: ScreenUtil().setWidth(180),
                child: Text(
                  '￥${cartProvider.allPrice}',
                  style: TextStyle(
                    color: Colors.red,
                    fontSize: ScreenUtil().setSp(36)
                  ),
                ),
              ),
            ],
          ),
          Container(
            width: ScreenUtil().setWidth(405),
            alignment: Alignment.centerRight,
            child: Text(
              '满10元免配送费，预购免配送费',
              style: TextStyle(
                fontSize: ScreenUtil().setSp(22),
                color: Colors.black38
              ),
            ),
          ),
        ],
      ),
    );
  }

  // 结算按钮
  Widget _submitButton() {
    return Container(
      width: ScreenUtil().setWidth(170),
      padding: EdgeInsets.only(left: 10),
      child: InkWell(
        onTap: (){},
        child: Container(
          padding: EdgeInsets.all(10.0),
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: Colors.red,
            borderRadius: BorderRadius.circular(3.0),
          ),
          child: Text(
            '结算(${cartProvider.allGoodsCount})',
            style: TextStyle(
             color: Colors.white 
            ),
          ),
        ),
      ),
    );
  }
}